Closed
Make mypy stricter and fix resulting type errors; add pyright#1356
Conversation
Co-authored-by: bact <128572+bact@users.noreply.github.com> Agent-Logs-Url: https://github.com/PyThaiNLP/pythainlp/sessions/f3ae2533-7ad3-40b6-9bbc-40197dd34ec5
Copilot
AI
changed the title
[WIP] Update mypy configuration for stricter checks and run validations
Make mypy stricter and fix resulting type errors; add pyright
Mar 22, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Enable three new mypy strictness flags and run pyright as an additional type checker, fixing all reported errors across the codebase.
What do these changes do
extra_checks,strict_bytes,strict_equality_for_none, andstrict_optionalto[tool.mypy]inpyproject.toml.pyrightconfig.json(basic mode) that suppresses false positives from uninstalled optional dependencies (torch, numpy, transformers, etc.) while keeping real checks enabled.What was wrong
mypy was missing three strictness flags. pyright had no config and had never been run — it surfaced:
list[LiteralString]assigned tolist[str](invariant list) intcc.py,tcc_p.py,pronounce.pyattn_energiesinthai2rom/thaig2p(noelsebranch onif/elifchains),th_m/days_in_monthinthai_lunar_dateOptional[X]globals) not narrowed after assignment —unigram.pytagger functions_tag_perceptron.pyload()(re-declaredclassesaslist[str]then called.add()on it),tokenization_small100.py,translate/NER.tag()return union not narrowed before tuple unpack innercut.pyTrie | Nonepassed whereTrie | list[str] | strexpected intokenize/core.pyHow this fixes it
pyproject.toml: three new mypy flags added in alphabetical order among existing flags.pyrightconfig.json: suppressesreportMissingImports,reportAttributeAccessIssue,reportCallIssue,reportGeneralTypeIssues,reportInvalidTypeForm,reportOperatorIssue,reportOptionalMemberAccess— all noise from optional deps absent in CI; mypy already covers these viaignore_missing_importsoverrides._tag_perceptron.py: removed redundant class-body declarations; fixedload()to assignset(w_td_c["classes"])(not retype aslist[str]); replacedprev, prev2 = self.STARTwith indexed access.unigram.py:cast(dict[str, str], _ORCHID_TAGGER)at return site — standard pattern for lazy-init globals pyright can't narrow.thai2rom.py/thaig2p.py: addedelse: raise ValueError("Unsupported attention method: …")to makeattn_energiesalways bound.thai_lunar_date.py:th_m = 0before loop;else: raise ValueErrorfor unknownlast_day.tokenization_small100.py: removed instance-level re-annotations for already-declared attributes;# pyright: ignore[reportRedeclaration]on property getter/setter pair (false positive from unresolvable transformers base class).budoux.py: explicitNoneguard after lazy init so pyright narrowsOptional[Any]→ non-None before.parse().Your checklist for this pull request
Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.